icon

Usetutoringspotscode to get 8% OFF on your first order!

C++

C++
Paper instructions:
1 Write a program to read lines and print only those containing a certain word. (For now, the word can be a constant string in the program.) The basic pattern (which I have to confess I have parroted exactly from K&R Sec. 4.1) is

while(there’s another line)
{
if(line contains word)
print the line;
}

2 Use the strstr function (mentioned in the notes) to look for the word. Be sure to include the line

#include <string.h>

at the top of the source file where you call strstr.
Rewrite the checkbook-balancing program from assignment 4 (exercise 6) to use the getwords function (from the notes) to make it easy to take the word “check” or “deposit”, and the amount, from a single line.
3 Rewrite the line-reversing function from assignment 4 (exercise 9) to use pointers.
4 Rewrite the character-counting function from assignment 5 (exercise 3) to use pointers.
5 Rewrite the string-concatenation program from assignment 5 (exercise 4) to call malloc to allocate a new piece of memory just big enough for the concatenated result. Don’t forget to leave room for the !
6 Rewrite the string-replacing function from assignment 5 (exercise 5) to use pointers.
7 Write a program to read lines of text up to EOF, and then print them out in reverse order. You can use getline to read each line into a fixed-size array (as we have been doing all along), but you will have to call malloc and make a copy of each line before you read the next one. Also, you will have to use malloc and realloc to maintain the “array” of character pointers which holds all of the lines.

You can leave a response, or trackback from your own site.

Leave a Reply

C++

1. Write a C++ function for each of the following.

(a) Given the matrix representing a relation on a finite set, determine whether the relation is reflexive and/or irreflexive.

(b) Given the matrix representing a relation on a finite set, determine whether the relation is symmetric and/or antisymmetric.

(c) Given the matrix representing a relation on a finite set, determine whether the relation is transitive.

2. Use the above functions to write a C++ program for solving each of the following computational problems.

(a) Display all the different reflexive and symmetric relations on a set of five elements.

(b) Display all the equivalence relations on a set of seven elements

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes